import { axios, noResInterceptors } from '../utils/request'



export function postAction(url,parameter, headers) {
  return axios({
    url: url,
    method:'post' ,
    data: parameter,
    headers: headers||{}
  })
}


export function httpAction(parameter = {}) {
  return axios(parameter)
}

//put
export function putAction(url,parameter) {
  return axios({
    url: url,
    method:'put',
    data: parameter
  })
}

//get
export function getAction(url,parameter) {
  return axios({
    url: url,
    method: 'get',
    params: parameter
  })
}


//deleteAction
export function deleteAction(url,parameter) {
  return axios({
    url: url,
    method: 'delete',
    params: parameter
  })
}


/**
 * 下载文件 用于excel导出
 * @param url
 * @param parameter
 * @returns {*}
 */
export function downFile(url,parameter, onDownloadProgress){
  return axios({
    url: url,
    params: parameter,
    method:'get' ,
    responseType: 'blob',
    onDownloadProgress:onDownloadProgress?onDownloadProgress:undefined,
    timeout:0
  })
}
// 上传文件
export function uploadFile(url, formData, onUploadProgress, headers={} ) {
  return axios({
    url: url,
    data: formData,
    headers:Object.assign({"Content-Type":"multipart/form-data"},headers),
    method:'post' ,
    responseType: 'json',
    onUploadProgress:onUploadProgress?onUploadProgress:undefined
  });
}

export function getActionNoResInterceptors(url,parameter) {
  return noResInterceptors({
    url: url,
    method: 'get',
    params: parameter
  })
}

